home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group96a.txt / 000090_icon-group-sender _Mon Apr 15 13:44:56 1996.msg < prev    next >
Internet Message Format  |  1996-09-05  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Mon, 15 Apr 1996 16:55:26 MST
  2. Date: Mon, 15 Apr 1996 13:44:56 -0700
  3. From: swampler@noao.edu
  4. Subject: Re: Making a list out of a generated sequence
  5. To: H.Lawson@tees.ac.uk
  6. Cc: icon-group@cs.arizona.edu
  7. Message-Id: <swampler-9603152044.AA00501630@orpheus.gemini.edu>
  8. In-Reply-To: <317260B1.7F93@tees.ac.uk>
  9. Errors-To: icon-group-errors@cs.arizona.edu
  10. Status: O
  11.  
  12.  
  13.  
  14. Hamish Lawson wrote:
  15. > Is there an easy way to make a list out of a generated sequence? I tried
  16. > enclosing the generator sequence in square brackets, as below, but it
  17. > doesn't appear to work.
  18. >    every write(sort([!"string"]))
  19. > Am I obliged to write a loop that appends each item of the generated
  20. > sequence to a list?:
  21. >    tempList := list()
  22. >    every tempList |||:= [!"string"]
  23. >    every write(!sort(tempList))
  24.  
  25. Yes, you must do something like this, though I'd use the put() function
  26. instead of list concatenation; you're building lots of temporary lists
  27. that aren't needed.  If you're into conciseness, you can do it as:
  28.  
  29.     every tempList := put([], !"string")
  30.  
  31.  
  32. > If so, it would seem to me to be a curious lack of symmetry that the
  33. > language provides the ! operator to generate elements of a list, but no
  34. > corresponding convenient mechanism for collecting into a list a
  35. > generated sequence of values.
  36.  
  37. Well, that's partly because of the nature of goal-directed evaluation.
  38. It sounds as though you'd like an operator that incorporates the
  39. functionality of the "every" expression.  I find the expression
  40.  
  41.    put([], expression)
  42.  
  43. sufficient for most such uses, and have only ever used it inside an
  44. every expression.  If you're fairly new to Icon, however, it might take
  45. some time to work out why this works (but when you do, you'll
  46. understand a little more about goal-directed evaluation!).
  47.  
  48. If you're not into conciseness, use:
  49.  
  50.    TempList := list()    # or TempList := []
  51.    every put(TempList, !"string)
  52.  
  53. instead.
  54.  
  55. -- 
  56. Steve Wampler - swampler@gemini.edu [Gemini 8m Telescopes Project (under AURA)]
  57. The Gods that smiled upon your birth are laughing now. -- fortune cookie
  58.